package com.ltz.web.login;

import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.ltz.dao.demo.DemoDao;
import com.ltz.model.User;
import com.ltz.service.login.LoginService;

@Controller
@RequestMapping(value="/login")
public class LoginController {
	@Resource
	private LoginService loginService;
	
	@RequestMapping(value="login",method=RequestMethod.GET)
	public String index(){
		return "/login/login";
	}
	@RequestMapping(value="doLogin",method=RequestMethod.POST)
	public String doLogin(Map map,HttpServletRequest request,String userName,String password){
		User user=loginService.doLogin(request,userName, password);
		user.setPassword("");//不需要存储密码
		request.getSession().setAttribute("user", user);
		map.put("user", user);
		if(null!=user){
			return "/main/main";
		}else{
			return "/login/login";
		}
	}
}
